""" Game interface """

from abc import *
from gameserver.service.exceptions.ttypes import *

class AbstractGame():
    """Abstract class for games"""

    __metaclass__ = ABCMeta

    def __init__(self, playersNnumber, admin, **gameMode):
        """ Initialization of the game """
        self.__playersNumber = playersNnumber;
        self.__currentPlayer = 0;
        self.__admin = admin;
        self.__players = list()
        self.set_mode(gameMode);

    @abstractmethod
    def set_mode(self, gameMode):
        """ Sets the mode of the game """
        pass

    @abstractmethod
    def check_move(self, player, **move_args):
        """ Checks if move is right """
        pass

    @abstractmethod
    def make_move(self, player, **move_args):
        """ Makes a move """
        pass

    @abstractmethod
    def save_history(self):
        """ Saves current game state """
        pass

    def is_player(self, id):
        return id in self.__players

    def add_player(self, id):
        if self.is_player(id):
            raise RegistrationError
        elif self.__playersNumber == len(self.__players):
            raise RegistrationError
        else:
            self.__players.append(id)
        return True

    def start(self, id):
        """Start the game"""
        if (self.__admin != id):
            raise AccessViolation
        if not self.is_player(id):
            raise NotRegistered
        self.__currentPalyer = self.__players[0]
        self.state = 'Running'
        return True

    def stop(self, id):
        """Start the game"""
        if (self.__admin != id):
            raise AccessViolation
        if not self.is_player(id):
            raise NotRegistered
        self.state = 'Stopped'
        return True

    @property
    def admin(self):
        return self.__admin

    @admin.setter
    def admin(self, admin):
        self.__admin = admin

    @property
    def currentPalyer(self):
        return self.__currentPlayer

    @property
    def palyers(self):
        return self.__players